var wxCharts = require('../../../utils/wxcharts.js');
var app = getApp();
var pieChart = null;
Page({
  data: {
    m1: 0,//奖金
    m2: 0,//红包
    m3: 0,//工资
    m4: 0,//兼职
    m5: 0,//办公
    m6: 0,//交通
    m7: 0,//娱乐
    m8: 0,//学习
    m9: 0,//餐饮
    m10: 0,//服饰
    m11: 0,//网购
    m12: 0,//日用
    m13: 0,//住房
    m14: 0,//社交
    m15: 0,//通讯
    m16: 0,//其他
    style: ["奖金", "红包", "工资", "兼职", "办公", "交通", "娱乐", "学习", "餐饮", "服饰", "网购", "日用", "住房", "社交", "通讯", "其他"]
  },
  touchHandler: function (e) {
    console.log(pieChart.getCurrentDataIndex(e));
  },
  onShow: function () {
    var that = this;
    wx.request({
      url: 'https://hi.slickghost.com/WebTest/Operate',
      data: {
        choice: 'programdata',
        year1: app.globalData.year1,
        month1: app.globalData.month1,
        year2: app.globalData.year2,
        month2: app.globalData.month2,
        openid: app.globalData.openid,
        in_or_out: 'outcome'
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (list) => {
        for (var i = 0; i < list.data.length; i++) {
         // console.log(list.data[i].tname);
         // console.log(list.data[i].money);
          if (list.data[i].tname == '奖金') {
            this.setData({
              m1: list.data[i].money*(-1)
            })
          }
          if (list.data[i].tname == '红包') {
            this.setData({
              m2: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '工资') {
            this.setData({
              m3: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '兼职') {
            this.setData({
              m4: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '办公') {
            this.setData({
              m5: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '交通') {
            this.setData({
              m6: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '娱乐') {
            this.setData({
              m7: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '学习') {
            this.setData({
              m8: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '餐饮') {
            this.setData({
              m9: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '服饰') {
            this.setData({
              m10: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '网购') {
            this.setData({
              m11: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '日用') {
            this.setData({
              m12: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '住房') {
            this.setData({
              m13: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '社交') {
            this.setData({
              m14: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '通讯') {
            this.setData({
              m15: list.data[i].money * (-1)
            })
          }
          if (list.data[i].tname == '其他') {
            this.setData({
              m16: list.data[i].money * (-1)
            })
          }

        }
        //console.log(this.data.style[0]);
        var windowWidth = 320;
        try {
          var res = wx.getSystemInfoSync();
          windowWidth = res.windowWidth;
        } catch (e) {
          console.error('getSystemInfoSync failed!');
        }
       // console.log(this.data.m2);
        pieChart = new wxCharts({
          animation: true,
          canvasId: 'pieCanvas2',
          type: 'pie',
          series: [{
            name: '奖金',
            data: this.data.m1,
          }, {
            name: '红包',
            data: this.data.m2,
          }, {
            name: '工资',
            data: this.data.m3,
          }, {
            name: '兼职',
            data: this.data.m4,
          }, {
            name: '办公',
            data: this.data.m5,
          }, {
            name: '交通',
            data: this.data.m6,
          }, {
            name: '娱乐',
            data: this.data.m7,
          }, {
            name: '学习',
            data: this.data.m8,
          }, {
            name: '餐饮',
            data: this.data.m9,
          }, {
            name: '服饰',
            data: this.data.m10,
          }
            , {
            name: '网购',
            data: this.data.m11,
          }
            , {
            name: '日用',
            data: this.data.m12,
          }
            , {
            name: '住房',
            data: this.data.m13,
          }
            , {
            name: '社交',
            data: this.data.m14,
          }
            , {
            name: '通讯',
            data: this.data.m15,
          }
            , {
            name: '其他',
            data: this.data.m16,
          }
          ],
          width: windowWidth,
          height: 300,
          dataLabel: true,
        })

      }
    })
  }
})